
#ifndef _READWRITE_3DS_H_
#define _READWRITE_3DS_H_

#include <BFile>
#include <BReadWrite>
#include <BGeometry>
#include <BElement>
#include <BNode>
#include <BScene>

#include "MateObj.h"

using namespace BWE;

class ReadWrite_obj : public BReadWrite
{
public:
	ReadWrite_obj();
	~ReadWrite_obj();

	virtual bool readObject(const BString& fileName, BObject* object);
	virtual bool writeObject(const BString& fileName, const BObject* object);

	virtual const BString& author() const;
	virtual const BString& version() const;
	virtual const BString& description() const;
	virtual const BString& log() const;

private:
	bool loadMtllib(const BString& mtlfile);
	MateObj* findMaterial(const BString& matName);

	void getIllum(int illum);
	bool convertTextToVector(const BString& text, int pos, BVector& vector);
	bool convertTextToCoord(const BString& text, int pos, BCoord& coord);
	bool convertTextToColor(const BString& text, int pos, BColor& color);

	bool readFace(const BString& text, int pos);

	bool finishGeometry(BShapeHolderArray& shapes);

private:
	BString					_fileName;
	BList<MateObjHolder>	_mates;

	BVectorArray*			_vs;
	BVectorArray*			_vns;
	BCoordArray*			_vts;

	BHolder<BGeometry>		_geometry;
	BNode*					_node;
	BString					_geomName;
	BElement*				_trigElement;
	BPieceArray*			_trigPieces;
	BElement*				_quadElement;
	BPieceArray*			_quadPieces;
	MateObj*				_mate;

	//convert buffer
	BString					_word;

	//read face value.
	BString					_segment;
	BString					_strIndex;

	BString			_author;
	BString			_version;
	BString			_description;
	BString			_log;
};

#endif